﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Tao.OpenGl;

namespace TaoFrm
{
    public class TetraDisplay
    {
        public static float rotateT = 0.0f;
        public static void Reshape(int width, int height)
        {

            float h = GetAspectRatio(width,  height);
            Gl.glViewport(0,0, width, height);
            Gl.glMatrixMode(Gl.GL_PROJECTION);
            Gl.glLoadIdentity();
            Glu.gluPerspective(30.0f, h, 1, 1000.0);
         //   Glu.gluLookAt(1, 0, 0, 0.5, 0.5, 0.5, 0, 1, 0);
           
            Gl.glMatrixMode(Gl.GL_MODELVIEW);
        //    Gl.glLoadIdentity();
            
        }

        private static float GetAspectRatio(int width,  int height)
        {
            if (height <= 0)
            {
                height = 1;
            }
            float h = (float)width / (float)height;
            return h;
        }
        public static void Init()
        {
            Gl.glShadeModel(Gl.GL_SMOOTH);
            Gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
            Gl.glClearDepth(1.0f);
            Gl.glEnable(Gl.GL_DEPTH_TEST);
            Gl.glDepthFunc(Gl.GL_LEQUAL);
	Gl.glHint(Gl.GL_PERSPECTIVE_CORRECTION_HINT, 
		  Gl.GL_NICEST);
           
        }
        public static void Display()
        {

            float dimension = 50.0f;
            Gl.glClear(Gl.GL_COLOR_BUFFER_BIT |
                 Gl.GL_DEPTH_BUFFER_BIT);
            Gl.glLoadIdentity();
            Glu.gluLookAt(100, -10, 10, 0.5, 0.5, 0.5, 0, 1, 0);
         //   Gl.glPushMatrix();
            Gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
            Gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
            Gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);
            Gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
            Gl.glBegin(Gl.GL_TRIANGLES);

            // Front
            Gl.glColor3f(0.0f, 1.0f, 1.0f);
            Gl.glVertex3f(-1.0f*dimension, 0,0);
            Gl.glColor3f(0.0f, 0.0f, 1.0f);
            Gl.glVertex3f(1.0f * dimension, 0, 0);
            Gl.glColor3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.5f * dimension, dimension, dimension);

            // Right Side Facing Front
            Gl.glColor3f(0.0f, 1.0f, 1.0f);
            Gl.glVertex3f(0.5f*dimension, dimension, 0);
            Gl.glColor3f(0.0f, 0.0f, 1.0f);
            Gl.glVertex3f(1.0f * dimension,0,0);
            Gl.glColor3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.5f * dimension, dimension, dimension);

            // Left Side Facing Front
            Gl.glColor3f(0.0f, 1.0f, 1.0f);
            Gl.glVertex3f(0.5f * dimension, dimension, 0);
            Gl.glColor3f(0.0f, 0.0f, 1.0f);
            Gl.glVertex3f(-1.0f * dimension, 0, 0);
            Gl.glColor3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.5f * dimension, dimension, dimension);

            // Bottom
            Gl.glColor3f(0.0f, 0.0f, 0.0f);
            Gl.glVertex3f(0.5f * dimension, dimension, 0);
            Gl.glColor3f(0.1f, 0.1f, 0.1f);
            Gl.glVertex3f(-1.0f * dimension, 0, 0);
            Gl.glColor3f(0.2f, 0.2f, 0.2f);
            Gl.glVertex3f(1.0f * dimension, 0, 0);

            Gl.glEnd();
            //Gl.glPopMatrix();
            //Gl.glFlush();
            rotateT += 0.2f;
        }
    }
}
